package com.sharemarking.application.common.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.sharemarking.application.common.dto.DictDto;
import com.sharemarking.application.common.entity.Dict;
import com.sharemarking.application.common.repository.DictRepo;

@Service
public class DictService {
	@Autowired
	private DictRepo dr;
	
	@Cacheable("dict")
	public List<DictDto> getDict(String type){
		List<Dict> list=dr.findAllByTypeOrderBySort(type);
		List<DictDto> target=new ArrayList<DictDto>();
		for(Dict dict:list){
			DictDto dd=new DictDto();
			dd.setLabel(dict.getLabel());
			dd.setValue(dict.getValue());
			target.add(dd);
		}
		return target;
	}
}
